package com.harmontronics.hanma.paas.paas.domain.tenant.repository.persistence;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.consts.DbConstants;
import com.harmontronics.hanma.paas.paas.consts.NumberEnum;
import com.harmontronics.hanma.paas.paas.domain.tenant.repository.mapper.HmTenantAppMapper;
import com.harmontronics.hanma.paas.paas.domain.tenant.repository.po.HmTenantAppPO;
import org.springframework.stereotype.Repository;


@Repository("hmTenantAppRepository")
public class HmTenantAppRepository extends ServiceImpl<HmTenantAppMapper, HmTenantAppPO> {

    public IPage<HmTenantAppPO> selectPage(QueryWrapper<HmTenantAppPO> queryWrapper, Page<HmTenantAppPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }


    public boolean appUniqueIdExists(String appUniqueId) {
        QueryWrapper<HmTenantAppPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("app_unique_id", appUniqueId);
        queryWrapper.last("limit 1");
        return baseMapper.selectOne(queryWrapper) != null;
    }

    public HmTenantAppPO findByAppUnique(String appUniqueId) {
        QueryWrapper<HmTenantAppPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("app_unique_id", appUniqueId);
        queryWrapper.last("limit 1");
        return baseMapper.selectOne(queryWrapper);
    }


    public List<HmTenantAppPO> findApps() {
        QueryWrapper<HmTenantAppPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("app_type", NumberEnum.TWO.getNum());
        queryWrapper.eq(DbConstants.DELETED, NumberEnum.ZERO.getNum());
        return baseMapper.selectList(queryWrapper);

    }

}